package com.ewhale.feitengguest.presenter.user.mine;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.ArticleDetailDto;
import com.ewhale.feitengguest.dto.HelpCenterDto;
import com.ewhale.feitengguest.view.user.mine.HelpCenterView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

import java.util.List;

public class HelpCenterPresenter extends IPresenter {

    public void loadlist( ) {
        mView.showProLoading();
        request(1, ApiHelper.USER_API.getHelpList(), null);
    }

    public void loadArticleDetails(HelpCenterDto helpCenterDto) {
        mView.showProLoading();
        request(2, ApiHelper.USER_API.getArticleDetails(helpCenterDto.id), helpCenterDto.name);
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((HelpCenterView) mView).showList((List<HelpCenterDto>) result);
                break;
                case 2:
                ((HelpCenterView) mView).showDetail((ArticleDetailDto) result,(String)data);
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }

}
